package com.eascs.web.o2o.quartz.test;

import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.slf4j.Logger;  
import org.slf4j.LoggerFactory;  

public class QuartzScheduleMain2 {

	 
    /** 
     *  
     * @throws Exception 
     */  
    public void run() throws Exception {  
        Logger log = LoggerFactory.getLogger(QuartzScheduleMain2.class);  
  
        log.info("------- Initializing ----------------------");  
  
        // First we must get a reference to a scheduler  
        //从调度管理器中获取调度对象  
        Scheduler sched = QuartzScheduleMgr.getInstanceScheduler();  
        log.info("------- Initialization Complete -----------");  
  
        // computer a time that is on the next round minute  
        Date runTime = new Date();  
  
        log.info("------- Scheduling Job  -------------------");  
  
        // define the job and tie it to our HelloJob class  
        //创建相关的job信息  
        JobDetail job = JobBuilder.newJob(HelloJob2.class)  
            .withIdentity("job2", "group2")  
            .build();  
          
        // Trigger the job to run on the next round minute  
        //创建一个触发器的名称  
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/5 * * * * ?");
        Trigger trigger = TriggerBuilder.newTrigger()  
            .withIdentity("trigger2", "group2"). withSchedule(scheduleBuilder) 
            .build();  
          
        // Tell quartz to schedule the job using our trigger  
        //设置调度相关的Job  
        sched.scheduleJob(job, trigger);  
        log.info(job.getKey() + " will run at: " + runTime);    
  
        log.info("------- Shutdown Complete -----------------");  
    }  
  
}
